package dao.impl;

import java.util.List;

import javax.annotation.Resource;

import model.User;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import dao.UserDao;
@Component("userDaoImpl")
public class UserDaoImpl implements UserDao {

	private HibernateTemplate hibernateTemplate ;
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}


	public boolean checkUserExistenceByName(String username) {
		List<User> users= hibernateTemplate.find("from User u where u.username='"+username+"'");
		
		if (users!=null && users.size()>0) {
			return true;
		}
		return false;
	}

	
	public void save(User u) {
		hibernateTemplate.save(u);
		
	}

	public List<User> getUsers() {
		
		return (List<User>)this.hibernateTemplate.find("from User");
	}

	public User loadById(int id) {
		return (User)this.hibernateTemplate.get(User.class, id);
	}

	

}
